library(sf)
library(ggplot2)
library(tidyverse)
library(gridExtra)
library(patchwork)
library(readxl)
library(haven)


###############################################################################################################
###############################################################################################################

setwd("")

# read data
match <- read_excel("raw/prussia_landinequality.xls") 

# read shapefile
shape <- st_read("raw/bismarckmap.shp")

shape <- shape %>% rename(bismarck_id=bsmrck_)


# merge, need to put shapefile first, so that geometry is kept
gdf <- merge(shape, match, by='bismarck_id')

gdf <- gdf %>% mutate(quantiles = as.factor(ntile(s_bigfarms, 10)))
p <- gdf %>% ggplot() + geom_sf(aes(fill = quantiles), size = 0.1)  +
  scale_fill_brewer(palette = "RdYlBu", name = "% Large farms", direction = -1, guide = guide_legend(nrow=2)) +
  theme_void() + theme(legend.position = "bottom")
p
pdf("output/figure1a.pdf")
plot(p)
dev.off()
